package com.cskaoyan.controller.admin;

import com.cskaoyan.model.admin.bo.BaseParam;
import com.cskaoyan.model.admin.vo.*;
import com.cskaoyan.service.admin.AdminOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.util.Map;

/**
 * @description:
 * @author: 牛犇
 * @date 2021/11/30 21:36
 */
@RestController
@RequestMapping("/admin/order")
public class AdminOrderController {

    @Autowired
    AdminOrderService adminOrderService;

    @RequestMapping("/detail")
    public BaseRespVo orderDetail(String id) {
        OrderDetailVo orderDetailVo;
        try {
            orderDetailVo = adminOrderService.orderDetail(id);
        } catch (IllegalArgumentException e) {
            return BaseRespVo.fail(402, "参数值不对");
        }
        return BaseRespVo.ok(orderDetailVo);
    }

    @RequestMapping("/list")
    public BaseRespVo orderList(BaseParam baseParam, String[] timeArray, String orderSn, String userId, Short[] orderStatusArray) throws ParseException {
        BaseDataListVo baseDataListVo = adminOrderService.orderList(baseParam, timeArray, orderSn, userId, orderStatusArray);
        return BaseRespVo.ok(baseDataListVo);
    }

    @RequestMapping("channel")
    public BaseRespVo channel() {
        ChannelVo[] channelVos = new ChannelVo[]{new ChannelVo("ZTO", "中通快递"), new ChannelVo("YTO", "圆通快递"), new ChannelVo("YD", "韵达速递"), new ChannelVo("YZPY", "邮政快递包裹"), new ChannelVo("EMS", "EMS"), new ChannelVo("DBL", "德邦快递"), new ChannelVo("FAST", "快捷快递")};
        return BaseRespVo.ok(channelVos);
    }

    @RequestMapping("/reply")
    public BaseRespVo orderReply(@RequestBody OrderReplyVo orderReplyVo) {
        try {
            adminOrderService.orderReply(orderReplyVo);
        } catch (IllegalArgumentException e) {
            return BaseRespVo.fail(622, "订单商品已回复");
        }
        return BaseRespVo.ok(null);
    }
    @RequestMapping("delete")
    public BaseRespVo orderDelete(@RequestBody Map map){
        Integer orderId = (Integer) map.get("orderId");
        adminOrderService.orderDelete(orderId);
        return BaseRespVo.ok(null);
    }
    @RequestMapping("/refund")
    public BaseRespVo orderRefund(@RequestBody Map map){
        return BaseRespVo.fail(602,"订单退款失败");
    }
}
